import React, { useEffect, useLayoutEffect, useState } from "react"
import { useFormField } from "../context/FormContext";
import { useMainContext } from "../context/MainContext"
import { useOnEventBus, publishEventBus, eventBus} from "../eventBus/eventBus";

export default function Textarea(props){
    const context2 = useMainContext();
    
    const [label, setLabel] = useState("年龄");

    const {
        value,
        onChange
    } = useFormField({
        fieldPath : "age"
    });

    useOnEventBus("label.update", (data)=>{
        console.log('setLabel(data);')
        setLabel(data);
    }, [label]);

    return <>
        <p>
            context2.loading: {context2?.loading + ""}
        </p>
        <p>
            context2.name: {context2?.name}
        </p>
        <p>evertBus监听label： {label}</p>
        <textarea
            value={value}
            onChange={(e)=>{
                onChange(e.target.value);
            }}
        ></textarea>
    </>
}